﻿
namespace Patterns4Net.Tests.PatternEnforcer.Core.Patterns.Regression
{
    using System;
    using NUnit.Framework;
    using Patterns4Net.Core.CecilExtensions;
    using Patterns4Net.Core.Patterns;
    using Patterns4Net.PatternEnforcer.Core.Patterns;

    [TestFixture]
    public class WrapperCheckerTest : PatternCheckerTestBase
    {
        [Test]
        [TestCase(typeof(DoesContainWrappedType))]
        [TestCase(typeof(DoesNotContainWrappedTypeAndDoesNotImplementTarget))]
        public void Tests_Without_TargetInterface(Type type)
        {
            var checker = new WrapperChecker<Proxy>();
            this.TestChecker(checker, type, new Proxy(type.GetTypeDefinition(), null, typeof(DateTime).GetTypeDefinition()));
        }

        [Test]
        [TestCase(typeof(DoesNotContainWrappedTypeAndDoesNotImplementTarget))]
        public void Test_With_Target_Interface(Type type)
        {
            var checker = new WrapperChecker<Proxy>();
            this.TestChecker(checker, type, new Proxy(type.GetTypeDefinition(), typeof(IComparable).GetTypeDefinition(), null));            
        }

        [PatternTest(false)]
        public class DoesNotContainWrappedTypeAndDoesNotImplementTarget
        {
        }

        [PatternTest(true)]
        public class DoesContainWrappedType
        {
            private DateTime wrapped;

            public DoesContainWrappedType(DateTime wrapped)
            {
                this.wrapped = wrapped;
            }

            public int Months
            {
                get { return this.wrapped.Month; }
            }
        }
    }
}
